<template>
  <div class="box">
    <h2>Son1 子组件 </h2>
    <h3>{{ $store.getters.filterList }}</h3>
    从vuex中获取的值: <label>{{ $store.state.totalCount }}</label>
   <!--直接通过模块名访问 $store.getters['模块名/xxx ']  -->
    <h4>user模块：{{ $store.getters['user/getFirstNmae'] }}</h4>
    <button @click="$store.dispatch('user/chanageNameAsync','异步李四')">
      修改用户名（异步）
    </button>
    <br>
      <button @click="add(1)">值 + 1</button>
      <button @click="add(5)">值 + 5</button>
      <button @click="add(10)">值 + 10</button>
      <br>
      <button @click="addcount(100)">值 + 100</button>
      <button @click="asyncCount">异步值 + 100</button>
    </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  name: 'Son1Com',
  methods: {
    // map映射
    ...mapMutations(['addCount']),
    // 外部通过commit调用store中的方法(mutations)
    add (payload) {
      this.$store.commit('addCount', payload)
    },
    asyncCount () {
      this.$store.dispatch('addCountAsync', 100)
    }
  }
}
</script>

<style lang="css" scoped>
  .box{
    border: 3px solid #ccc;
    width: 400px;
    padding: 10px;
    margin: 20px;
  }
  h2 {
    margin-top: 10px;
  }
</style>
